/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package BubbleSort;

import java.util.Random;

/**
 *
 * @author trang
 */
public class BubbleSort {
    public static void main(String[] args) {
        int []n;
        n=new int[10];
        Random myRan =new Random();
//        Initialize the array
        for (int i = 0; i < n.length; i++) {
            n[i]=myRan.nextInt();
        }

//        print the array's initial order
        System.out.println("Before sorting ");
        for (int i = 0; i < n.length; i++) {
            System.out.println("n [" + i + "] =" +n[i]);

        }
        boolean sorted =false;
//        Sort array
        while (!sorted) {
            sorted=true;
            for (int i = 0; i < n.length-1; i++) {
                if (n[i]>n[i+1]) {
                    int temp=n[i];
                    n[i]=n[i+1];
                    n[i+1]=temp;
                    sorted=false;

                }
            }
        }
        System.out.println("After sorting :");
        for (int i = 0; i < n.length-1; i++) {
             System.out.println("n [" + i + "] =" +n[i]);
        }

    }

}
